<template>
	<div class="gateWay">
		<van-nav-bar title="网关信息" left-arrow="" @click-left='goBack()'></van-nav-bar>

		<div class="area">
			<van-search placeholder="搜索网关名称" show-action v-model="searchData">
				<div slot="action" @click="onSearch">搜索</div>
			</van-search>
			<van-dropdown-menu>
				<van-dropdown-item @change='onSearch' v-model="value" :options="option1" />
			</van-dropdown-menu>

			<div class="info">
				<div class="cell-info" v-for="(item,i) in gatewayList" :key='i'>
					<van-cell title="网关名称" :value="item.gwname"></van-cell>
					<van-cell title="网管序列号" :value="item.id"></van-cell>
					<van-cell title="网关所在地" :value="item.place"></van-cell>
					<van-cell title="通信状态" :value="(item.cmdid===103||item.cmdid===3)?'已通讯':'未通讯'"></van-cell>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
	import {Toast} from 'vant'
	export default {
		data() {
			return {
				gatewayList:[],
				searchData:'',
				value:'',
				option1:[
					{text:'请选择网关状态',value:''},
					{text:'已通讯',value:103},
					{text:'未通讯',value:1}
				]
			}
		},
		created() {
			this.getGatewayList()
		},
		watch:{
			searchData(newVal){
				if(!newVal) this.onSearch()
			}
		},
		methods: {
			getGatewayList(){
				this.$axios.get(this.url.getGatewayList).then(res=>{
					if(res.data.status === 200){
						this.gatewayList = res.data.msg
						console.log(this.gatewayList)
						if(this.gatewayList.length === 0){
							Toast.success({message:'暂无数据',duration:900})
						}
					}
				})
			},
			onSearch() {
				let params = new FormData()
				params.append('name',this.searchData)
				this.$axios.post(this.url.selectGateway,{gwname:this.searchData,cmdid:this.value}).then(res=>{
					if(res.data.status === 200){
						this.gatewayList = res.data.msg
						if(this.gatewayList.length === 0){
							Toast.fail({message:'暂无数据',duration:900})
						}
					}
				})
			},
			goEditGateway() {
				this.$router.push({
					name: 'editGateway'
				})
			}
		}
	}
</script>

<style scoped="scoped">

	.title {
		color: #222222;
	}

	.operation {
		margin-left: 10.5rem;
	}

	.van-button {
		line-height: 1.8rem;
		height: 1.8rem;
	}

	.info {
		padding: .6rem;

	}

	.cell-info {
		box-shadow: 2px 2px 5px #ADADAD;
		padding-bottom: .8rem;
		margin-bottom: 1rem;
	}

	van-button {
		color: #777;
	}

	.van-button--default {
		border: none;
	}

	.keywords {
		font-size: .8rem;
		color: #999999;
		margin-bottom: .8rem;
	}
</style>
